package com.example.constellation.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.constellation.R;
import com.example.constellation.bean.StarBean;
import com.example.constellation.utils.AssetsUtils;

import java.util.List;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class fg1adapter extends BaseAdapter {

    private Context context;
    private List<StarBean.StarinfoBean> mdata;
    private Map<String, Bitmap> logomap;

    public fg1adapter(Context context, List<StarBean.StarinfoBean> mdata) {
        this.context = context;
        this.mdata = mdata;
        logomap=AssetsUtils.getLogoimgmap();
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int position) {
        return mdata.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder holder=null;
        if (convertView==null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.itemfg1gv,null);
            holder=new Viewholder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (Viewholder) convertView.getTag();
        }
        //获取指定位置的数据
        StarBean.StarinfoBean Bean = mdata.get(position);
        holder.itemfg1txt.setText(Bean.getName());
        //获得图片的名称，根据名称在内存中查找
        String logoname = Bean.getLogoname();
        Bitmap bitmap = logomap.get(logoname);
        holder.itemfg1img.setImageBitmap(bitmap);
        return convertView;
    }

    //item中控件进行声明与初始化
    class Viewholder{
        CircleImageView itemfg1img;
        TextView itemfg1txt;
        public Viewholder(View view){
            itemfg1img=view.findViewById(R.id.itemfg1img);
            itemfg1txt=view.findViewById(R.id.itemfg1txt);
        }
    }
}
